package com.wyd.flowable.custom;

import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.TaskHelper;
import org.flowable.task.api.DelegationState;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

import java.util.Set;

/**
 * 委托任务 参考
 * @see org.flowable.engine.impl.cmd.DelegateTaskCmd
 */
public class DelegateTaskCmdCustom extends NeedsActiveTaskCmd<Object> {
    private Set<String> userIds;

    public DelegateTaskCmdCustom(String taskId, Set<String> userIds) {
        super(taskId);
        this.userIds = userIds;
    }

    @Override
    protected Object execute(CommandContext commandContext, TaskEntity task) {
        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
//        if (task.getProcessDefinitionId() != null && Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, task.getProcessDefinitionId())) {
//            Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
//            compatibilityHandler.add(taskId, identityId, identityIdType, identityType);
//            return null;
//        }

        task.setDelegationState(DelegationState.PENDING);
        if (task.getOwner() == null) {
            task.setOwner(task.getAssignee());
        }
        TaskHelper.changeTaskAssignee(task, null);

        return null;
    }
}
